package com.itheima.controller;

import com.itheima.domain.Result;
import com.itheima.domain.pojo.Emp;
import com.itheima.domain.pojo.LoginInfo;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@RestController
public class LoginController {

    @Autowired
    private EmpService empService;

    /**
     * 登录功能
     * @param logInfoMap
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody Map<String,Object> logInfoMap) {
        log.info("员工来登录啦 , {}", logInfoMap);
        LoginInfo loginInfo = empService.login(logInfoMap);
        return loginInfo != null ? Result.success(loginInfo) : Result.error("用户名或密码错误~");
//        if(loginInfo != null){
//            return Result.error("登录失败");
//        }
//        return Result.error("用户名或密码错误~");
    }

}
